package com.hgsf.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Random;


public class Verify {
	static Color getColor() {
		Random random = new Random();
		int r = random.nextInt(256);
		int g = random.nextInt(256);
		int b = random.nextInt(256);
		return new Color(r, g, b);
	}
	public static String getCheckCode() {
		return (int)(Math.random()*9000)+1000+"";
	}

	public static BufferedImage createImage(String s) {
		BufferedImage image = new BufferedImage(80,30 ,BufferedImage.TYPE_INT_RGB);
		Graphics graphics = image.getGraphics();
		graphics.fillRect(0, 0, 80, 30);
		for(int i = 0;i<60;i++) {
			Random random = new Random();
			int xBegin = random.nextInt(80);
			int yBegin = random.nextInt(30);
			int xEnd = random.nextInt(xBegin+10);
			int yEnd = random.nextInt(yBegin+10);
			graphics.setColor(getColor());
			graphics.drawLine(xBegin, yBegin, xBegin+xEnd, yBegin+yEnd);
			
		}
		graphics.setFont(new Font("微软雅黑", Font.BOLD, 18));
		graphics.setColor(getColor());
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < s.length(); i++) {
			sb.append(s.charAt(i)+" ");
		}
		graphics.drawString(sb.toString(), 15, 20);
		graphics.dispose();
		return image;
	}
	public static void writeImage(OutputStream out, BufferedImage image) {
		try {
			ImageIO.write(image, "jpeg", out);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws FileNotFoundException {
		int a[]={48,848,6,96,665,2,16,1,59,156,16,6};
		bubbleSort(a);
		System.out.println(Arrays.toString(a));
	}

	public static void bubbleSort(int []arr) {

		for(int i =0;i<arr.length-1;i++) {
			for(int j=0;j<arr.length-i-1;j++) {
				if(arr[j]>arr[j+1]) {
					int temp = arr[j];

					arr[j]=arr[j+1];

					arr[j+1]=temp;
				}
			}
		}
	}
}
